<template>
  <el-dialog
    width="30%"
    :visible.sync="localVisible"
    title="新增分类"
    @close="handleClose"
    ><span
      ><el-input placeholder="请输入分类名称" v-model="categoryName"></el-input
    ></span>
    <span slot="footer"
      ><el-button type="primary" @click="formSubmit">确定</el-button
      ><el-button @click="handleClose">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { create_category } from "@/api/home/nav";

export default {
  name: "New_category",
  props: {
    visible: {
      type: Boolean,
      required: true,
    },
  },
  data() {
    return {
      localVisible: this.visible,
      categoryName: "", // 将数组改为字符串
    };
  },
  methods: {
    async formSubmit() {
      await create_category({
        category: this.categoryName,
      });
      this.$emit("created");
      this.handleClose();
    },
    handleClose() {
      this.localVisible = false;
      this.$emit("update:visible", false);
    },
  },
};
</script>

<style lang="scss"></style>

